//获取包名
package com.codeyang.controller.system;
/**
 * 描述: 操作日志
 *
 * @author CodeYang_Site
 * @version 2021/5/5 22:09
 */
//设置一个实体变量获取我们输入的类名
//小驼峰变量

import com.codeyang.annos.Log;
import com.codeyang.dto.OperLogDto;
import com.codeyang.enums.BusinessType;
import com.codeyang.service.OperLogService;
import com.codeyang.utils.AjaxResult;
import com.codeyang.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Arrays;

// 取值 {实体变量名}

@RestController
@RequestMapping("/system/operLog")
public class OperLogController {

    @Autowired
    private OperLogService operLogService;

    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("/listForPage")
    public AjaxResult listForPage(OperLogDto operLogDto) {
        DataGridView dataGridView = operLogService.lisPage(operLogDto);
        return AjaxResult.success("数据加载成功", dataGridView.getData(), dataGridView.getTotal());
    }


    /**
     * 删除数据
     *
     * @param ids 根据id删除数据
     * @return 是否删除成功
     */
    @DeleteMapping("/deleteOperLogByIds/{ids}")
    public AjaxResult deleteOperLogByIds(@PathVariable("ids") Long[] ids) {
        boolean flag = operLogService.removeByIds(Arrays.asList(ids));
        return flag ? AjaxResult.success() : AjaxResult.fail("删除失败");
    }

    /**
     * 清空操作
     *
     * @return
     */
    @DeleteMapping("/clearOperLog")
    public AjaxResult clearOperLog() {
        boolean flag = operLogService.remove(null);
        return flag ? AjaxResult.success() : AjaxResult.fail("清空失败");
    }

    /**
     * 错误日志的演示
     * |
     * 以下三个对象无法做记录
     *  It is illegal to call this method if the current request is not in asynchronous mode
     *  在记录日志时JSON序列化这三个对象 有异常,因为以下三个对象无法被正常序列化,需要跳过
     * @param request
     * @param response
     * @param session
     * @return
     */
    @GetMapping("/error/log")
    @Log(title = "日志记录-错误日志的记录",businessType = BusinessType.UPDATE)
    public  AjaxResult logError(HttpServletRequest request, HttpServletResponse response, HttpSession session){
        return  AjaxResult.success("ok");
    }


}
